/** @file Geometry.js
@brief The geometry methods to manage multi-device and screen orientation

The Geometry methods should be imported in the qml documents binding
the methods returning values to properties. Thus the file Geometry
needs to be instantiated and should not include the clause .pragma
Binding methods with qml properties when the screen size changes (i.e. rotating)
the bound values are automatically updated.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

/**
    @var var size_tolerance
    @brief Percentage reduction area of the screen

    Size tolerance is the real portion of the screen accepted before the sized area
    will be considered too small. This is useful to grant a minimum of flexibility
    to the different screen sized depending on the device type and the rotation angle.
    The tolerance value is constant for all the devices and sizes.
*/
var size_tolerance = 0.95;

/**
    @var var device_screen_Small, device_screen_Normal, device_screen_Large, device_screen_ExtraLarge
    @brief Redefinition of the screen device types.
*/
var device_screen_Small = 0;
var device_screen_Normal = 1;
var device_screen_Large = 2;
var device_screen_ExtraLarge = 3;

/**
    @fn getDeviceWidth()
    @brief Return the physical width of the device running the application

    Depending on the rotation of the device the value is inverted. This is because
    we do not know previously what is the standard device orientation.

    @return Width pixels of the device
*/
function getDeviceWidth() {

    console.log("getDeviceWidth - Screen rotation = " + screen.rotation);
    console.log("                - Screen.displayWidth = " + Screen.displayWidth);
    console.log("                - Screen.displayHeight = " + Screen.displayHeight);

    if (screen.rotation == 0)
        return Screen.displayWidth
    else
        return Screen.displayHeight
}

/**
    @fn getDeviceHeight()
    @brief Return the physical height of the device running the application

    Depending on the rotation of the device the value is inverted. This is because
    we do not know previously what is the standard device orientation.

    @return Height pixels of the device
*/
function getDeviceHeight() {

    console.log("getDeviceHeight - rotation = " + screen.rotation);

    if (screen.rotation == 0)
        return screen.displayHeight
    else
        return screen.displayWidth
}

/**
    @fn getObjectHeight(constrains, subobjects)
    @brief get the height of a object based on the screen size

    The constrains parameter tells what area of the physical screen
    should not be overlapped. This mean that the free screen area
    for the object should be [device_screen - constrains]

    The subobject is the minimum size required to grant the correct
    visibility of the components of the object.

    For a certain device the method return the screen area value if the
    object is shorter. This means that for this direction the flickable
    property has no effect. If the object should be greater than the usable
    device screen portion the method returns the minimum object size
    This means that the object in this direction will be flickable.

    Note that the object from where this method is called is defined flickable
    (with automatic direction detection) a-priori. Then if the involved size
    has the same height of the screenarea no flicking is active.

    @param constrains The size reduction of the pysical device size
    @param subobjects The minimum size of the object on the screen

    @return The calculated size
  */
function getObjectHeight(constrains, subobjects) {
    var screenarea;
    screenarea = getDeviceHeight();
    if ( ( (screenarea - constrains) * size_tolerance) > subobjects)
        return screenarea - constrains;
    else
        return subobjects;
}

/**
    @fn getObjectWidth(constrains, subobjects)
    @brief get the width of a object based on the screen size

    The constrains parameter tells what area of the physical screen
    should not be overlapped. This mean that the free screen area
    for the object should be [device_screen - constrains]

    The subobject is the minimum size required to grant the correct
    visibility of the components of the object.

    For a certain device the method return the screen area value if the
    object is shorter. This means that for this direction the flickable
    property has no effect. If the object should be greater than the usable
    device screen portion then the method returns the minimum object size
    This means that the object in this direction will be flickable.

    Note that the object from where this method is called is defined flickable
    (with automatic direction detection) a-priori. Then if the involved size
    has the same height of the screenarea no flicking is active.

    @param constrains The size reduction of the pysical device size
    @param subobjects The minimum size of the object on the screen

    @return The calculated size
  */
function getObjectWidth(constrains, subobjects) {
    var screenarea;
    screenarea = getDeviceWidth();
    if ( ( (screenarea - constrains) * size_tolerance) > subobjects)
        return screenarea - constrains;
    else
        return subobjects;
}

/**
    @fn getButtonSpacing()
    @brief Spacing between buttons when grouped of aligned.

    @return Device dependendent value in pixels
*/
function getButtonSpacing() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 2;
        break;
    case device_screen_Normal:
        return 4;
        break;
    case device_screen_Large:
        return 8;
        break;
    case device_screen_ExtraLarge:
        return 12;
        break;
    }
}

/**
    @fn getFormBorder()
    @brief Form border size.

    @return Device dependendent value in pixels
*/
function getFormBorder() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 2;
        break;
    case device_screen_Normal:
        return 3;
        break;
    case device_screen_Large:
        return 5;
        break;
    case device_screen_ExtraLarge:
        return 7;
        break;
    }
}

/**
    @fn getFieldSpacing()
    @brief Spacing between fields when grouped or aligned.

    @return Device dependendent value in pixels
*/
function getFieldSpacing() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 2;
        break;
    case device_screen_Normal:
        return 4;
        break;
    case device_screen_Large:
        return 8;
        break;
    case device_screen_ExtraLarge:
        return 12;
        break;
    }
}

/**
    @fn getFieldHeight()
    @brief The field height in pixels.

    Note that when this size is used in horizontal alignment
    with other elements (e.g. fields) it is best to maintain the same value

    @return Device dependendent value in pixels
*/
function getFieldHeight() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 30;
        break;
    case device_screen_Normal:
        return 35;
        break;
    case device_screen_Large:
        return 40;
        break;
    case device_screen_ExtraLarge:
        return 45;
        break;
    }
}

/**
    @fn getButtonHeight()
    @brief The button height in pixels

    @return Device dependendent value in pixels
*/
function getButtonHeight() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 25;
        break;
    case device_screen_Normal:
        return 35;
        break;
    case device_screen_Large:
        return 40;
        break;
    case device_screen_ExtraLarge:
        return 45;
        break;
    }
}

function getBigButtonHeight() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 35;
        break;
    case device_screen_Normal:
        return 50;
        break;
    case device_screen_Large:
        return 55;
        break;
    case device_screen_ExtraLarge:
        return 65;
        break;
    }
}

function getRadius() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 7;
        break;
    case device_screen_Normal:
        return 9;
        break;
    case device_screen_Large:
        return 14;
        break;
    case device_screen_ExtraLarge:
        return 16;
        break;
    }
}

// Standard text font size. This value is used in all cases where
// the fond sizes are not related to the contained object i.e. fields,
// buttons etc.
function getFontPoints() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 7;
        break;
    case device_screen_Normal:
        return 10;
        break;
    case device_screen_Large:
        return 12;
        break;
    case device_screen_ExtraLarge:
        return 18;
        break;
    }
}

// The separator is used distantiating a
// group of coherent elements.
function getSeparator() {
    switch(qtComplex.screenCategory) {
    case device_screen_Small:
        return 14;
        break;
    case device_screen_Normal:
        return 20;
        break;
    case device_screen_Large:
        return 35;
        break;
    case device_screen_ExtraLarge:
        return 40;
        break;
    }
}


